package com.csea.app.config;

import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MySaTokenConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加登录校验拦截器
        registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
                .addPathPatterns("/app/**")          // 拦截应用接口
                .excludePathPatterns(                // 排除认证接口
                        "/app/user/auth/login",
                        "/app/user/auth/register",
                        "/app/user/auth/logout",
                        "/app/idiom/complexSearch",
                        "/app/idiom/simpleSearch",
                        "/app/idiom/search/**",
                        "/public/**"
                );
    }
}